package com.ht.demo.admin.controller.system;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.enums.OperateTypeEnum;
import com.ht.demo.common.page.PageBO;
import com.ht.demo.common.pojo.bo.system.SysPostBO;
import com.ht.demo.common.pojo.qto.system.SysPostQTO;
import com.ht.demo.service.annotation.LoggerInfo;
import com.ht.demo.service.annotation.Permission;
import com.ht.demo.service.manager.system.SysPostManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author hdengxian
 * @Date 2023/5/26 16:21
 */
@RestController
@RequestMapping("${basePath}/system/post")
public class SysPostController {
    @Resource
    private SysPostManager sysPostManager;

    @Permission(permissionId = "system:post:add", desc = "新增岗位")
    @LoggerInfo(title = "岗位管理", operateType = OperateTypeEnum.INSERT)
    @PostMapping("/insert")
    public ResultData<Boolean> insertPost(@RequestBody SysPostBO post) throws AppException {
        return new ResultData<>(sysPostManager.insertPost(post));
    }

    @Permission(permissionId = "system:post:edit", desc = "修改岗位")
    @LoggerInfo(title = "岗位管理", operateType = OperateTypeEnum.UPDATE)
    @PutMapping("/updateById")
    public ResultData<Boolean> updatePost(@RequestBody SysPostBO post) throws AppException {
        return new ResultData<>(sysPostManager.updatePost(post));
    }

    @Permission(permissionId = "system:post:remove", desc = "删除岗位")
    @LoggerInfo(title = "岗位管理", operateType = OperateTypeEnum.DELETE)
    @DeleteMapping("/delete/{sysPostIds}")
    public ResultData<Boolean> deletePost(@PathVariable Long[] sysPostIds) throws AppException {
        return new ResultData<>(sysPostManager.deletePost(sysPostIds));
    }

    @GetMapping("/getById/{sysPostId}")
    public ResultData<SysPostBO> getPostById(@PathVariable Long sysPostId) throws AppException {
        return new ResultData<>(sysPostManager.getPostById(sysPostId));
    }

    @GetMapping("/allList")
    public ResultData<List<SysPostBO>> getPostList() throws AppException {
        return new ResultData<>(sysPostManager.getPostList());
    }

    @GetMapping("/forPage")
    public ResultData<PageBO<SysPostBO>> getPostForPage(SysPostQTO qto) throws AppException {
        return new ResultData<>(sysPostManager.getPostForPage(qto));
    }

}
